import request from "@/api/request";
import type { SunnyModule } from "@/types/sunnyModule/type";
import type { SunnyProject } from "@/types/sunnyProject/type";
import type { Axios, AxiosPromise } from "axios";

export function listProjectsApi(): AxiosPromise<SunnyProject[]> {
  return request({
    url: "/sunnyProject",
    method: "get",
  });
}

export function getOneProjectApi(projectId: number): AxiosPromise<SunnyProject> {
  return request({
    url: "/sunnyProject/" + projectId,
    method: "get",
  });
}

export function addProjectApi(data: SunnyProject): AxiosPromise<any> {
  return request({
    url: "/sunnyProject",
    method: "post",
    data,
  });
}

export function updateProjectApi(data: SunnyProject): AxiosPromise<any> {
  return request({
    url: "/sunnyProject",
    method: "put",
    data,
  });
}

export function deleteProjectApi(projectId: number): AxiosPromise<any> {
  return request({
    url: "/sunnyProject/" + projectId,
    method: "delete",
  });
}

export function listModulesInProjectApi(
  projectId: number
): AxiosPromise<SunnyModule[]> {
  return request({
    url: "/sunnyProject/" + projectId + "/modules",
    method: "get",
  });
}
